package com.redare.dev.smart.generator.service.impl;

import com.redare.dev.smart.generator.sdk.GeneratorSysSdk;
import com.redare.dev.smart.generator.sdk.pojo.GeneratorSys;
import com.redare.dev.smart.generator.sdk.pojo.form.GeneratorSysForm;
import com.redare.dev.smart.generator.service.service.GeneratorSysService;
import com.redare.devframework.common.pojo.CommonResult;
import com.redare.devframework.common.pojo.Page;
import com.redare.devframework.common.validation.ValidationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 业务系统 impl
 *
 * @author yangqiangyu
 * @date 2021-08-27 15:19:22
 */
@Service(value = "com.redare.dev.smart.generator.impl.GeneratorSysSdkImpl")
public class GeneratorSysSdkImpl implements GeneratorSysSdk {

    @Autowired
    GeneratorSysService generatorSysService;

    @Override
    public CommonResult<Boolean> addGeneratorSys(GeneratorSysForm.Add form) {
        CommonResult result = ValidationUtils.simpleValidate(form);
        if (result.isNotSuccess()) {
            return result;
        }
        boolean bool = generatorSysService.addGeneratorSys(form);
        return CommonResult.returnBoolWrapper(bool, "添加失败");
    }

    @Override
    public CommonResult<Boolean> editGeneratorSys(GeneratorSysForm.Edit form) {
        CommonResult result = ValidationUtils.simpleValidate(form);
        if (result.isNotSuccess()) {
            return result;
        }
        boolean bool = generatorSysService.editGeneratorSys(form);
        return CommonResult.returnBoolWrapper(bool, "编辑失败");
    }

    @Override
    public CommonResult<Boolean> deleteGeneratorSys(GeneratorSysForm.Del form) {
        CommonResult result = ValidationUtils.simpleValidate(form);
        if (result.isNotSuccess()) {
            return result;
        }
        boolean bool = generatorSysService.deleteGeneratorSys(form);
        return CommonResult.returnBoolWrapper(bool, "删除失败");
    }

    @Override
    public CommonResult<List<GeneratorSys>> findGeneratorSysList(GeneratorSysForm.Search form) {
        List<GeneratorSys> list = generatorSysService.findGeneratorSysList(form);
        return CommonResult.returnSuccessWrapper(list);
    }

    @Override
    public CommonResult<List<GeneratorSys>> findGeneratorSysList(GeneratorSysForm.Search form, int curPage, int pageSize) {
        List<GeneratorSys> list = generatorSysService.findGeneratorSysList(form, curPage, pageSize);
        return CommonResult.returnSuccessWrapper(list);
    }

    @Override
    public CommonResult<Page<GeneratorSys>> findGeneratorSysPage(GeneratorSysForm.Search form, int curPage, int pageSize) {
        Page<GeneratorSys> page = generatorSysService.findGeneratorSysPage(form, curPage, pageSize);
        return CommonResult.returnSuccessWrapper(page);
    }

    @Override
    public CommonResult<GeneratorSys> getGeneratorSys(GeneratorSysForm.Get form) {
        CommonResult result = ValidationUtils.simpleValidate(form);
        if (result.isNotSuccess()) {
            return result;
        }
        GeneratorSys info = generatorSysService.getGeneratorSys(form);
        if (info == null) {
            return CommonResult.returnFailsWrapper("数据不存在");
        }
        return CommonResult.returnSuccessWrapper(info);
    }


}

